from common import deploy_choices
from django.db import models


class VmInfo(models.Model):
    """
    Vm配置
    """

    name = models.CharField(
        "名称",
        max_length=60,
        default="",
    )

    createAt = models.DateTimeField(
        "创建时间",
        null=True,
        auto_now_add=True,
    )

    updateAt = models.DateTimeField(
        "更新时间",
        null=True,
        auto_now=True,
    )

    vmIntranet = models.CharField(
        "vm_intranet",
        max_length=60,
        default="",
        help_text="vm_master",
    )

    vmExtranet = models.CharField(
        "vm_extranet",
        max_length=60,
        default="",
        help_text="vm_extranet",
    )

    initVm = models.CharField(
        "部署master",
        max_length=60,
        default="to_deploy",
        null=True,
        choices=deploy_choices,
    )
    initVmSsh = models.CharField(
        "initVmSsh",
        max_length=60,
        default="to_deploy",
        null=True,
        choices=deploy_choices,
    )
    installNginx = models.CharField(
        "installNginx",
        max_length=60,
        default="to_deploy",
        null=True,
        choices=deploy_choices,
    )
    installApisix = models.CharField(
        "installApisix",
        max_length=60,
        default="to_deploy",
        null=True,
        choices=deploy_choices,
    )
    installKafka = models.CharField(
        "installKafka",
        max_length=60,
        default="to_deploy",
        null=True,
        choices=deploy_choices,
    )
    adminKey = models.CharField(
        "adminKey",
        max_length=60,
        default="",
        null=True,
    )

    pubkey = models.TextField(
        "pubkey",
        default="",
        help_text="pubkey",
        null=True,
    )

    def __str__(self):
        return "%s" % (self.name,)

    class Meta:
        verbose_name = "Vm配置"
        verbose_name_plural = verbose_name
        db_table = "VmInfo"


class KeyInfo(models.Model):
    """
    Key配置
    """

    esMasterRel = models.ForeignKey(
        VmInfo,
        on_delete=models.PROTECT,
        verbose_name="esMasterRel",
        help_text="esMasterRel",
        related_name="VmInfo_esMasterRel",
        default=None,
        null=True,
        blank=True,
    )
    name = models.CharField(
        "名称",
        max_length=60,
        default="",
    )

    createAt = models.DateTimeField(
        "创建时间",
        null=True,
        auto_now_add=True,
    )

    def __str__(self):
        return "%s" % (self.name,)

    class Meta:
        verbose_name = "KeyInfo配置"
        verbose_name_plural = verbose_name
        db_table = "KeyInfo"
